#pragma once
#include <Windows.h>
#include "BridgeManager.h"
#include <string>

class CtrlManager
{
private:
	CRITICAL_SECTION criticalSection;
	BridgeManager* bridgeManager;
	list<string> pendingData;

	HANDLE hCtrlThread;
	HANDLE hStoppedEvent;

public:
	CtrlManager(BridgeManager* manager);
	~CtrlManager();

	HANDLE Start();
	void Stop();
	void WaitingForStopped();
	void HandlePackage(const char *buf, int length);

	BOOL HasPendingData();
	string GetOnePendingData();

	void ReportStatus();
	void QueryBridges();
	void AddBridge(Bridge* bridge);
	void DeleteBridge();
	void DeleteBridgeByName(const char *cncName);

	HANDLE GetStoppedEventHandle();

private:
	static DWORD WINAPI CtrlThreadFunc(LPVOID param);

};

